<?php
/**
 * Create a new Customer
 *
 * @author
 */

use Fox\Generator;
use Fox\Html\TabPanel\Tab;
use Fox\Html\Wrapper;
use Fox\Html\TabPanel;
use Nawa\Customer;
use Fox\Html\Screen;

$screen = new Screen('eCustomer','create');
$tabPanel = new TabPanel('pCustomer');
$wMasterData = new Wrapper('wMasterData');

$blName = Xview::instance()->component('customers', 'name');
$wMasterData->add($blName);
$blAddress = Xview::instance()->component('customers', 'address');
$wMasterData->add($blAddress);
$tabPanel->add(new Tab('tMasterData',Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_MASTER_DATA),$wMasterData));

$screen->add($tabPanel);

if($screen->submitted())
{
	$inputs = $screen->get();
	// Check Duplicates ?
	if(!$screen->errors())
	{
		// Load Customizing Point

	}

	if(!$screen->errors())
	{
		try {
			// Default Values
			$inputs['type'] = Customer::TYPE_BASIC;
			$inputs['name1'] = $inputs['first_name'].' '.$inputs['last_name'];
			// Create Customer
			$object = new Customer();
			$object->setFields($inputs);
			$object->create();
			$id = $object->getId();
			Fox\Message::Success(Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_CREATE,$object->name1));
			Xview::instance()->redirect(Generator::url('customers','update',null,array('customerid' => $id)));
		}
		catch(Fox\Object\Exception\Save $e)
		{
			Fox\Message::Error($e->getMessage());
		}
	}
}
$screen->mainTitle('<div class="page-title"><p>'.Msg(Nawa\Messages::BUNDLE,Nawa\Messages::TITLE_CREATE_CUSTOMER).'</p></div>');
echo $screen->Display();